package org.springblade.modules.ehb.wrapper;

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.modules.ehb.vo.EhbPolicyVO;
import org.springblade.modules.system.service.IFileService;
import org.springblade.modules.system.vo.AttachmentVO;

import java.util.ArrayList;
import java.util.List;

public class EhbPolicyWrapper extends BaseEntityWrapper<EhbPolicyVO, EhbPolicyVO> {

	private static IFileService fileService;

	static {
		fileService = SpringUtil.getBean(IFileService.class);
	}

	public static EhbPolicyWrapper build() {
		return new EhbPolicyWrapper();
	}

	@Override
	public EhbPolicyVO entityVO(EhbPolicyVO entity) {
		if (Func.isNotEmpty(entity.getFiles())) {
			List<AttachmentVO> attachments = fileService.selectLibraryFiles(entity.getFiles(), entity.getId());
			entity.setAttachmentList(attachments);
		} else {
			entity.setAttachmentList(new ArrayList<>());
		}
		return entity;
	}
}
